package com.sofly.controller.group3;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sofly.entity.DataGrid;
import com.sofly.entity.OutStockInfo;
import com.sofly.service.group3.IOutStockService;

/**
 * 
* <p>Title:OutStockController </p>
* <p>Description: </p>
* <p>Company: </p> 
* @author 苏艳
* @date 上午11:39:12
 */
@Controller
public class OutStockController {

	
	@Autowired
	private IOutStockService outStockService;
	
	@Autowired
	private DataGrid dataGrid;
	
/**
 * 
 * @param page
 * @param rows
 * @param outStockDate
 * @return
 */
	@RequestMapping(value="/href/outStockInfoList")
	@ResponseBody
	public DataGrid getOutStockInfoList(String page, String rows,String outStockDate){
		
		int page1 = Integer.parseInt(page);
		int rows1 = Integer.parseInt(rows);
		List<OutStockInfo> list = new ArrayList<>();
		int total = 0;
		if(outStockDate==null||outStockDate==""){
			list = outStockService.getOutStockList((page1-1)*rows1,rows1);
			total = outStockService.getCount();
			dataGrid.setRows(list);
			dataGrid.setTotal(total);
		}else{
			list = outStockService.getOutStockListByDate(outStockDate,(page1-1)*rows1,rows1);
			total = outStockService.getCount1(outStockDate);
			dataGrid.setRows(list);
			dataGrid.setTotal(total);
		}
		return dataGrid;
		
	}
	/**
	 * 
	 * @param outStockInfo
	 * @return
	 */
	@RequestMapping("/href/addOutStockInfo")
	@ResponseBody
	public int addOutStockInfo(OutStockInfo outStockInfo){
		int i = outStockService.addOutStock(outStockInfo);
		
		return i;
	}
	/**
	 * 
	 * @param productId
	 * @return
	 */
	@RequestMapping("/href/SearchOutstockinfo")
	@ResponseBody
	public OutStockInfo getOutstockinfo(String productId){
		
		OutStockInfo outStockInfo = outStockService.getOutStock(productId);
		
		return outStockInfo;
	}
}
